home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
RESEDIT_
/
ICON_PIC
/
ICON_PIC.C
Wrap
Text File
|
1991-10-16
|
6KB
|
182 lines
/******************************************************************************
COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
All rights reserved
Icon Resource Picker
Modifications for THINK C by Maarten Meijer, 1991
Some modifications by Erik A. Johnson (johnsone@uxh.cso.uiuc.edu) for
THINK C (5.0.1).
*******************************************************************************/
/* This is the Icon resource picker example.
The general scheme is that a List structure is created whose cells
contain the ID's of this resource type. A drawproc is installed in the List
record which is called to display the resource. */
#ifdef THINK_C
#if THINK_C == 5
/* these following are included in the THINK C precompiled MacHeaders file */
/*#include <Types.h>*/
/*#include <Menus.h>*/
/*#include <Resources.h>*/
/*#include <Memory.h>*/
/*#include <Lists.h>*/
#else
/* these following are included in the THINK C precompiled MacHeaders file */
/*#include <MacTypes.h>*/
/*#include <MenuMgr.h>*/
/*#include <ResourceMgr.h>*/
/*#include <MemoryMgr.h>*/
/*#include <ListMgr.h>*/
#endif
#else
#include <types.h>
#include <memory.h>
#include <menus.h>
#include <resources.h>
#include <lists.h>
#endif
#include "ResEd.h"
#define iconMenuID 10 /* Just one of ResEdit's menus. */
#define listCellSizeH 0x38
#define listCellSizeV 0x42
/* Needs to be 2 wide so that I can always tell a 2 dimensional list from a normal text list. */
#define minIconsPerRow 2
#define ICONMinWindowWidth (minIconsPerRow * listCellSizeH) + theScrollBar
#define ICONMinWindowHeight listCellSizeV
typedef struct IconPickRec {
ParentHandle father; /* Back ptr to dad */
Str255 fName; /* Max 255 characters. */
WindowPtr wind; /* Picker window */
Boolean rebuild; /* Flag set to indicate that window should be rebuilt */
Boolean spare1; /* Not used here */
unsigned char windowType;
ResType theResType; /* Type of the resource being picked or edited. */
short theResFile; /* The home resfile of the window. */
short codeResID; /* Resource ID of the RSSC resource containing the picker or editor. */
Handle spare; /* Not used here */
ResType rType; /* Type for this picker */
long rSize; /* size of a null resource */
short minWindowWidth; /* Use when the window is grown. */
short minWindowHeight;
ListHandle instances; /* List of instances */
short nInsts; /* Number of instances */
unsigned char viewBy; /* Current view type */
Boolean showAttributes; /* Show attrs in window? */
ResType ldefType; /* Which LDEF to use */
MenuHandle theViewMenu; /* The picker view menu */
long viewMenuMask; /* Which items are enabled? */
Cell cellSize; /* Size for special view. */
MenuHandle iconMenu; /* Our menu */
} IconPickRec;
typedef IconPickRec *IconPickPtr;
typedef IconPickPtr *IconPickHandle;
#ifdef THINK_C
#pragma mark _prototypes
pascal void EditBirth(Handle thing, ParentHandle dad);
pascal void PickBirth(ResType t, ParentHandle dad);
pascal void DoEvent(EventRecord *evt, IconPickHandle pick);
pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick);
pascal void DoMenu(short menu, short item, IconPickHandle pick);
pascal Boolean IsThisYours (Handle thing, PickHandle pick);
pascal short ResEdID(void);
#endif
/* Used only for editors. */
pascal void EditBirth(Handle thing, ParentHandle dad)
{SysBeep(20);
#pragma unused (thing, dad)
}
/* *********************************************************************************** */
pascal void PickBirth(ResType t, ParentHandle dad)
{
IconPickHandle pick;
IconPickPtr p; /* temp ptr for *pick */
MenuHandle theIconMenu;
SysBeep(20);
pick = (IconPickHandle)NewHandle(sizeof(IconPickRec));
SysBeep(20);
p = *pick;
p->father = dad; /* Back ptr to dad */
p->rType = t; /* Resource type that I understand */
p->viewBy = viewBySpecial; /* Special means we have our own LDEF to draw the icons */
p->ldefType = t; /* Which LDEF do we use? */
p->cellSize.h = listCellSizeH; /* Set the size of the cell. */
p->cellSize.v = listCellSizeV;
p->minWindowWidth = ICONMinWindowWidth;
p->minWindowHeight = ICONMinWindowHeight;
SysBeep(20);
/* Setup the list and create the window. */
if (!DoPickBirth(noColor, true, graphical2DPicker, ResEdID(), (PickHandle)pick))
DisposHandle ((Handle)pick); /* Error */
else {
theIconMenu = GetMenu(iconMenuID);
DetachResource((Handle)theIconMenu); /* Get our own copy of the menu. */
(*pick)->iconMenu = theIconMenu;
}
}
/* *********************************************************************************** */
/* Everything is taken care of for us by PickEvent. */
pascal void DoEvent(EventRecord *evt, IconPickHandle pick)
{
PickEvent(evt, (PickHandle)pick);
if (evt->what == activateEvt) {
if (evt->modifiers & activeFlag)
InsertMenu((*pick)->iconMenu, 0);
else
DeleteMenu(iconMenuID);
DrawMBarLater(false);
}
}
/* *********************************************************************************** */
/* Everything is taken care of for us by PickInfoUp */
pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick)
{
PickInfoUp(oldID, newID, pick);
}
/* *********************************************************************************** */
pascal Boolean IsThisYours (Handle thing, PickHandle pick)
{
#pragma unused (thing, pick)
return false;
}
/* *********************************************************************************** */
/* Everything is taken care of for us by PickMenu. */
pascal void DoMenu(short menu, short item, IconPickHandle pick)
{
if (menu == iconMenuID) {
/* Do something with the menu */
}
else {
if ((menu == fileMenu) && (item == closeItem)) {
DeleteMenu(iconMenuID);
DrawMBarLater(false);
DisposHandle((Handle)(*pick)->iconMenu);
}
PickMenu(menu, item, (PickHandle)pick);
}
}